/**
 * Created by jacky on 15/11/11.
 */

define(function(require){

    //全局CRM
    require('../../c/base/index');
    //导航
    require('../../c/nav/index');

    var home = {
        init : function() {
            $("#item_center").attr("href",CRM.getOuterUrl('/itemcenter/crm/item/index.htm'));
            $("#search").attr("href",CRM.getOuterUrl('/search/configcenter/'));
            this.queryCurrent();
            this.getUserInfoById();
        },
        /**
         * 获取用户信息
         */
        getUserInfoById: function () {
            var self = this;
            CRM.request({
                url: CRM.getOuterUrl('/member/getUserbyUserId.do?userId=' + $.cookie('_uk')),
                type: 'get',
                async : false,
                success: function (data) {
                    if (data.status) {
                        if(data.entry.level >= 600){
                            $("#charts").attr("href",CRM.getOuterUrl('/dw/www/base/index.html'));
                            $("#charts").show();
                        }

                    }
                }
            });
        },
        queryCurrent : function(){
            CRM.request({
                "type": 'POST',
                "url": CRM.API.queryCurrent,
                "dataType": "json",
                contentType: "application/json",
                "success": function (req) {
                    if(req.status) {
                        $("#order_count").text(req.entry.todayOrderCount);
                        $("#order_price").text(req.entry.todayOrderPrice/100);
                        $("#order_chart").show();
                    }else{
                        $("#order_chart").hide();
                    }
                }
            });
        }
    };

    home.init();

});